#include <iostream>
#include <vector>
using namespace std;
int main()
{
    int T = 0;
    cin >> T;
    while(T--)
    {
        int n = 0, k = 0;
        string str;
        cin >> n >> k >> str;
        int res = 0;
        for(int i = 0; i < n; ++i)
        {
            if(i >= 2 && str[i - 2] == 'W' && str[i - 1] == 'W' && str[i] == 'W')
            {
                res += k;
            }
            else if(str[i] == 'W')
            {
                ++res;
            }
            else
            {
                --res;
            }
        }
        cout << res << endl;
    }
    return 0;
}